/**
 * Timer.js
 * 
 * Timer class, will be used to record timing while drawing
 */

var Timer = function()
{
	/**
	 * The time when the timer is launched
	 */
	this.start_ticks;
	
	/**
	 * The time recorded when the timer was paused
	 */ 
	this.paused_ticks;
	
	/**
	 * Property: Whether the timer is paused or not
	 */ 
	this.paused;
	
	/**
	 * Property: Whether the timer is enabled or not
	 */ 
	this.started;
	
	/**
	 * Function : Starts the timer
	 */ 
	
	this.start = function()
	{
		this.started = true;
		
		this.paused = false;
		
		this.start_ticks = (new Date).getTime();
	};
	
	/** 
	 * Function : Stops the timer
	 */
	this.stop = function()
	{
		this.started = false;
		
		this.paused = false;
	};

	/**
	 *  Get the number of milliseconds since the timer was started
	 *	Or recovers the number of milliseconds since the timer was paused
	 */
	this.get_ticks = function()
	{
		if (this.started)
		{
			if (this.paused)
			{
				return this.paused_ticks;
			}
			else
				return (new Date).getTime() - this.start_ticks;
		}
		return 0;
	};
	
	/**
	 * 
	 */
	this.pause = function()
	{
		if (this.started && !this.paused)
		{
			this.paused = true;
			
			this.paused_ticks = (new Date).getTime() - this.start_ticks;
		}
	};
	
	/**
	 * 
	 */
	this.unpause = function()
	{
		if (this.paused)
		{
			this.paused = false;
			
			this.start_ticks = (new Date).getTime() - this.paused_ticks;
			
			this.paused_ticks = 0;
		}
	};
	
	/**
	 * 
	 */
	this.is_started = function()
	{
		return this.started;
	};
	
	/**
	 * 
	 */
	this.is_paused = function()
	{
		return this.paused;
	};
};